package edu.ccut.saturn.authority.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;

public class ListFilter extends DefaultComponent {
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		
		List<Map<String, String>> list = (List<Map<String, String>>)parameterContext.getParameterValue(0);
		String filterDesc = (String)parameterContext.getParameterValue(1);
		String filter = (String)parameterContext.getParameterValue(2);
		
		parameterContext.setParameter(3, filterList(list, filterDesc, filter));
	}
	
	private List<Map<String, String>> filterList(List<Map<String, String>> list, String filterDesc, String filter){
		
		List<Map<String, String>> result = new ArrayList<Map<String,String>>();
		if(list != null){
			for(Map map : list){
				if(!filter.equals(map.get(filterDesc))){
					result.add(map);
				}
			}			
		}
		
		return result;
		
	}
}